import React, { useState, useEffect } from 'react'


export default function App() {
  let [opacity, setOpacity] = useState(1)

  // 初始化的时候设置一个定时器
  useEffect(() => {
    const opacityTimer = setInterval(() => {
      opacity -= 0.1
      if (opacity <= 0) {
        opacity = 1
      }
      setOpacity(opacity)
    },100)
    return () => {
      clearInterval(opacityTimer)
    }
  }, [])

  return (
    <div>
      <h1 style={{ opacity }}>嗨嗨嗨嗨嗨</h1>
    </div>
  )
}
